(function () {
    'use strict';

    angular
        .module('SURF')
        .controller('A01D02Controller', A01D02Controller);

    A01D02Controller.$inject = ['$scope', 'A01D02Service','$translate','$http'];


    function A01D02Controller($scope, A01D02Service,$translate,$http) {
        setMenuActivite('a01','a01d02');

        $scope.version_no = getTime();






        A01D02Service.getAllLine().then(
            function (answer) {
                var response = answer.data;
                if (response.error_flg == 0) {
                    $scope.lines = response.lines;
                } else {
                    showCommonDialog(response.msg,2);
                }
            }, function (error) {
                $scope.error = error;
            });




        //用户信息初始化
        var agentInfoBean = {};

        //提交按钮对应事件
        $scope.submitForm = saveNewUserInfo;

        function saveNewUserInfo() {
            if(isNull($scope.lineInfo)){
                showCommonDialog("请选择产线",2);
                return;
            }

                agentInfoBean.line_id = $scope.lineInfo;
                agentInfoBean.version_no = $scope.version_no;

            A01D02Service.saveVersion(agentInfoBean).then(
                function (answer) {
                    var response = answer.data;
                    if (response.error_flg == 0) {
                        showCommonDialog(response.msg,1);
                    }else {
                        showCommonDialog(response.msg,2);
                    }
                }, function (error) {
                }
            )
        };




        $('#datepicker').datepicker({
            autoclose: true
        });

        function getTime(){
            var currDate = new Date();
            var d = new Date();
            var YMDHMS = d.getFullYear() +""+ (d.getMonth()+1) +""+  d.getDate() + "" + d.getHours() + "" + d.getMinutes() + "" + d.getSeconds();
            return YMDHMS;
        }
    }


})();
